<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib uri="http://www.framework.com/taglib" prefix="frame"%>
  <head>
	<title>公共平台 </title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<!-- 样式文件的引入 -->

	<script type="text/javascript">
     var requestUrl="http://${basePath}:${port}${ctx}/business/projectmanage/leader/establishInput?projectId=${project.id}&r="+new Date().getTime();
	</script>
	<style type="text/css">
		li{
			padding-top:8px;
		}
		.st{
		 display:none;
		}
	</style>
</head>
<body>
	<form action="${ctx}/business/projectmanage/leader/establishsave" method="post"  enctype="multipart/form-data" id="addProjectsDataForm">
		<%-- <input type="hidden" value="${rows }" name="rows" id="rows"> --%>
		<input type="hidden" name="len" id="len">
		<input type="hidden" name="id" id="id" value="${project.id }">
		<input type="hidden" name="noteText" id="noteText" value="${project.noteText }">
		<%--<input type="hidden" name="responseFile" id="responseFile" value="${project.responseFile }">--%>
		<input type="hidden" name="budgetMenuData" id="budgetMenuData" value=""/>
		<div id="file" align="center"   class="easyui-layout">
			<h1>网上竞价文件</h1>
			<hr />
			<div class="easyui-panel" data-options="border:true,title:'基本信息'" style="padding:6px;margin-bottom: 6px">
				<table class="infoTable" style="margin-top: 0px;width:100%">
					<tr>
						<th class="key" text-align:left>项目名称：</th>
						<td colspan="3">${project.name}</td>
					</tr>
					<tr>
						<th class="key" width="10%" text-align:left>项目编码：</th>
						<td width="40%">${project.code}</td>
						<th class="key" width="10%" align="left">项目类型：</th>
						<td width="40%">${project.catagoryName }</td>
					</tr>
					<tr>
						<th class="key" align="left">采购内容：</th>
						<td colspan="3">${project.buyContent}</td>
					</tr>
					<tr>
						<th class="key" align="left">采购人：</th>
						<td>${project.operater}</td>
						<th class="key" align="left">委托单位：</th>
						<td>${project.agentName}</td>
					</tr>
					
					<tr>
						<th class="key" align="left">项目负责人姓名：</th>
						<td>${project.manageName}</td>
					<th class="key">项目预算(元)：</th>
						<td>
							<fmt:formatNumber value="${project.budgetAmount}" type="currency" pattern=".00#"/>
						</td>	
					</tr>
					
					<tr>
						<th class="key" align="left">付款方式：</th>
						<td>${project.payType}</td>
					<th class="key">采购单位：</th>
						<td>${project.buyName}</td>	
					</tr>
			</table>
			</div>

			<div class="easyui-panel" data-options="border:true,title:'项目基本要求'" style="padding:6px;margin-bottom: 6px">	
				<table class="infoTable">	
					<tr>
						<th class="key" > 供货地点：</th>
			            <td><input type="text"  class="easyui-validatebox" data-options="required:true" name="deliveryPoint" value="${project.deliveryPoint }"/></td>
			            <th class="key">供货期限：</th>
						<td>
						<input class="easyui-validatebox" data-options="required:true" name="deliveryLimit" maxlength="100" value="${project.deliveryLimit}" />
						</td>
					</tr>
					<tr>
						<th class="key">投标人保证金金额(元)：</th>
						<td colspan="3">
							<input type="text"  class="easyui-validatebox" data-options="required:true,validType:['priceDecimal']"  name="promissMoney" 
							value="<fmt:formatNumber value="${project.promissMoney }" type="currency" pattern="0.00#"/>" />
						</td>
					</tr>
					<tr>
						<th class="key">是否资质后审：</td>
						<td colspan="3">
							<input type="radio" name='isAfterAudit' onclick="isAfterAuditClick(1);" value="true" ${project.isAfterAudit==true||project.isAfterAudit==null?"checked":"" }/>是  &nbsp;&nbsp;
							<input type="radio" name='isAfterAudit' onclick="isAfterAuditClick(0);" value="false" ${project.isAfterAudit==false?"checked":"" }/>否
						</td>
					</tr>
				</table>	
			</div>
		
			<div class="easyui-panel" data-options="border:true,title:'投标人资格'" style="padding:6px;margin-bottom: 6px">	
				<table  class="infoTable">	
						<th  class="key">投标人资格：</td>
						<td>
							<textarea style="height:80px;" rows="5" cols="75" id="othereRequire" name="othereRequire"
							oninput="checkLength('othereRequireRemarkError',200,'othereRequire')" onpropertychange="checkLength('othereRequireRemarkError',200,'othereRequire')" onkeyup="checkLength('othereRequireRemarkError',200,'othereRequire')">${project.othereRequire}</textarea>
							<font color="red"><br />注：200个字符以内，还可以输入<span class="input_font" id="othereRequireRemarkError">${200-fn:length(project.othereRequire)}</span>个字符</font>
						</td>
						</tr>
						
				</table>	
			</div>
		
	
			<div class="easyui-panel" data-options="border:true,title:'报价设置'" style="padding:6px;margin-bottom: 6px">
				<table class="infoTable">
					<tr>
						<th class="key" >编制审核确认时间：</td>
						<td >
							<input class="easyui-datetimebox"  editable="false" data-options="required:true
								,validType:['dateTimeMoreCurrentCompare','isWorkDayToValidTime[\'${ctx }\']']" name="validTime"
							 	id="validTime" value="${project.validTime==null?buyerSureTime:project.validTime }"/>
						</td>
						<th class="key" cosplan="2">报价截止时间：</td>
						<td id="bidStartDateTr">
							<input type="text" class="easyui-datebox" editable="false"  name="bidStartDateStr" id="bidStartDateStr" 
							value="${project.bidStartTime }" data-options="required:true"/> -
							<select name='bidStartTimeStr' id="bidStartTimeStr" class="easyui-combobox" style="width:50px" data-options="required:true
							,validType:['isWorkDay[\'${ctx }\']']">
								<option value="" ></option>
								<option value='09' ${project.bidStartTime.getHours()==09?"selected='selected'":""}>09</option>
								<option value='15' ${project.bidStartTime.getHours()==15?"selected='selected'":""}>15</option>
							</select> 点 <font color="red">注：非工作日不允许设置项目开标</font>
						</td>
					</tr>
					<tr>
						<th class="key">报价方式：</td>
						<td colspan="3">
							<input type="radio" name='bidType' value="0" ${project.bidType==0||project.bidType==null?"checked":"" }/>金额  &nbsp;&nbsp;
							<input type="radio" name='bidType' value="1" ${project.bidType==1?"checked":"" }/>费率
						</td>
					</tr>
					<tr id="noAfterAudit" class="${project.isAfterAudit?'':'st' }">
						<th class="key">资质后审时间：</td>
						<td colspan="3">
							<input type="text" style="width:150px;" class="easyui-datebox" editable="false"  name="afterAuditDateStr" id="afterAuditDateStr" 
							value="${project.afterAuditDate }" data-options="required:true
							,validType:['isWorkDayToDate[\'${ctx }\']','afterAuditTime[\'bidStartDateStr\']']"/> -
							<select name='afterAuditTimeStr' id="afterAuditTimeStr" class="easyui-combobox" style="width:50px" 
							data-options="required:true">
								<option value='09' ${project.afterAuditDate==null||project.afterAuditDate.getHours()==09?"selected='selected'":""}>09</option>
								<option value='15' ${project.afterAuditDate.getHours()==15?"selected='selected'":""}>15</option>
							</select> 点 <font color="red">注：非工作日不允许设置后审</font>
						</td>
					</tr>
				</table>
			</div>

			<div class="easyui-panel" data-options="border:true,title:'采购需求'" style="padding:6px;margin-bottom: 6px">
					<table class="infoTable">
						<tbody>
							<tr>
							<th align="right" width="15%">采购需求：</th>
							<td style="border-right: none" width="35%">
								<div id="fileQueue" style="margin: 10px 0px 0px 10px">
									<input type="file" name="uploadify" id="uploadify" data-options="required:true"/>
									<p style="color: #aaaaaa;width: auto">
						1、按住Ctrl可选择多个文件上传;<br/>
						2、可上传*.rar;*.zip;*.doc;*.docx;*.xls;*.xlsx;*.jpg;*.png;*.gif;*.bmp;*.pdf;*.dwg;*.DXF;*.DWT;*.dws类型文件<br/>
						</p>
								</div>
							</td>
							<td style="border-left: none" colspan="2">
								<c:forEach items="${resList}" var="res">
									<c:if test="${res.functionFlog==8}">
										<div><a class="easyui-linkbutton" href="javascript:showOpenFile('${ctx }','${res.id}',requestUrl);"  >${res.oldName}</a> <span style="cursor: pointer;" onclick="deleteFile(this,'${res.id}');"><img src="${ctx }/commons/themes/icons/cancel.png"/></span></div>
									</c:if>
								</c:forEach>
							</td>
						</tr>
						</tbody>
					</table>		
			</div>
		
			<div class="easyui-panel" data-options="border:true,title:'中标人须提交的竞价资料'" style="padding:6px;margin-bottom: 6px">				
				<textarea style="height:80px;" rows="20" cols="133" id="responseFile2" name="responseFile"
						  oninput="checkLength('responseFileRemarkError',1000,'responseFile2')" onpropertychange="checkLength('responseFileRemarkError',1000,'responseFile2')" onkeyup="checkLength('responseFileRemarkError',1000,'responseFile2')">${project.responseFile}</textarea>
				<font color="red"><br />注：1000，还可以输入<span class="input_font" id="responseFileRemarkError">${1000-fn:length(project.responseFile)}</span>个字符</font>
			</div>
		
		
		<div align="center" style="margin-top: 25px;margin-bottom: 20px">
			<a href="javascript:void(0);" id="generateWorld"  class="easyui-linkbutton" iconCls="icon-chart" plain="true"><strong>生成Word</strong></a>
			<a class="easyui-linkbutton" id="establishFile" href="javascript:void(0);"  >无</a><br/>
		</div>
	</form>
</body>

<script >
	$(function(){
		var resIds = "";
		<c:forEach items="${resList}" var="res">
		resIds += ",${res.id}";
		</c:forEach>
		
		//初始化生成world按钮旁的竞价文件预览
		var bidFileId="";
		var bidFileName="无";
		<c:forEach items="${resList}" var="res">
		<c:if test="${res.functionFlog==5}">
			bidFileId="${res.id}";
			bidFileName="${res.oldName}";
		</c:if>
		</c:forEach>
		$("#establishFile").attr("href","javascript:showOpenFile('${ctx}','"+bidFileId+"','"+requestUrl+"');");
		$("#establishFile").html(bidFileName);
		
		
		$('#budgetMenuData').val(resIds);
		//年月控件
		/*$("#socialSecurityBeginTime,#socialSecurityEndTime").datebox({  //#qualifyFromDateStr,#qualifyEndDateStr,
            formatter: function(date) {
                var y = date.getFullYear();  
                var m = date.getMonth() + 1;  
                return y + '-' + (m < 10 ? ('0' + m) : m);  
            },  
            parser: function(s) {  
                if (!s) {  
                    return new Date();  
                }  
                var ss = s.split('-');  
                var y = parseInt(ss[0], 10);  
                var m = parseInt(ss[1], 10);  
                if (!isNaN(y) && !isNaN(m)) {  
                    return new Date(y, m - 1);  
                } else {  
                    return new Date();  
                }  
            }  
        });*/
		
		
		
	    //初始化响应文件信息
	   /*var responseFile=$("#responseFile").val();
	   $.each(responseFile.split("@"),function(index,data){
	    	if(data!=""){
	 	   		var _len = $("#tab4 tr").length;
	 			$("#len4").val(_len + 1); 
	  			if("竞价内容（必须与报价表内容（品名、品牌与型号、数量、单价、合计）一致，具体填写详见竞价内容简表"==data){//竞价内容
				   $("#tab4").append(
							"<tr id="+_len+" align='center'>"
							+ "<td width='15%'>"
							+ _len
							+ "</td>"
							+"<td class='key' align='left' width='85%' style='padding-left:30px;'>"
							+ "<textarea rows='3' cols='90' class='responseFile noEdit' name='data"+_len+"' id='data"+_len+"' onblur='noEdit(this)'>"+data+"</textarea>"
							+"</td>"
							+ "</tr>");
	  			}else{
				   $("#tab4").append(
							"<tr id="+_len+" align='center'>"
							+ "<td width='15%'>"
							+ _len
							+ "</td>"
							+"<td class='key' align='left' width='85%' style='padding-left:30px;'>"
							+ "<textarea rows='3' cols='90' class='responseFile' name='data"+_len+"' id='data"+_len+"' oninput=\"checkLength('remarkError"+_len+"',100,'data"+_len+"')\" "
							+ "onpropertychange=\"checkLength('remarkError"+_len+"',100,'data"+_len+"')\" onkeyup=\"checkLength('remarkError"+_len+"',100,'data"+_len+"')\">"+data.replace("-","")+"</textarea>"
							+ "<font color='red'><br />注：100个字符以内，还可以输入<span class='input_font' id='remarkError"+_len+"'>"+(100-data.length)+"</span>个字符</font>"
							+"</td>"
							+ "</tr>");
			   }
	 		}
		});*/

		//初始化社保缴纳时间、合同时间
		var socialSecurityBegin=$("#socialSecurityBeginTime").val();
		if(socialSecurityBegin==""){
			//初始化社保缴纳时间合同时间
			var curr_time = new Date();
			$("#socialSecurityEndTime").val(curr_time.pattern("yyyy-MM"));
			curr_time.setMonth(curr_time.getMonth() - 3);
			$("#socialSecurityBeginTime").val(curr_time.pattern("yyyy-MM"));
		}
	    
	  
	});
	

	$(function(){
		//需求清单
		$("#uploadify").uploadify({
			'height'        : 27,   
            'width'         : 80,    
            'buttonText'    : '选择附件',
            'queueID': 'fileQueue',//队列的ID
            'queueSizeLimit':5,// 附件附列长度
			'swf': '${ctx}/commons/js/uploadify/uploadify.swf',
			'uploader':'${ctx}/business/projectmanage/upload;jsessionid=${pageContext.session.id}?functionFlog=8',// 上传时请求的后台处理的controller
			'cancelImg': '${ctx}/commons/js/uploadify/uploadify-cancel.png',
			'method':'post',  
			'folder': '',
			'preventCaching' : true,
			'fileTypeExts' :'*.rar;*.zip;*.doc;*.docx;*.xls;*.xlsx;*.jpg;*.png;*.gif;*.bmp;*.pdf;*.dwg;*.DXF;*.DWT;*.dws',
			'auto': true,
			'multi': true,//是否可多选
			'removeCompleted' : false,
			'successTimeout' : 55555,
			'onUploadSuccess':function(file, data, response){
				$('#' + file.id).find('.data').html(' 上传完毕');
				$('#budgetMenuData').val($('#budgetMenuData').val() + "," + data);
				var cancel=$('#fileQueue .uploadify-queue-item[id="' + file.id + '"]').find(".cancel a");
				if (cancel) {
				   cancel.attr("rel", data);
				   cancel.click(function () {
					   var cancelData = cancel.attr("rel");
		               var  budgetMenuData = $('#budgetMenuData').val();
		               var index = budgetMenuData.indexOf(","+cancel.attr("rel"))
		               if(index != -1){
		            	   budgetMenuData = budgetMenuData.replace(","+cancelData,"");
		            	   $('#budgetMenuData').val(budgetMenuData);
		               }
				   });
				}
			},
			'onSelectError':function(file, errorCode, errorMsg){
				switch(errorCode) {
					case -110:
						//this.queueData.errorMsg="文件 ["+file.name+"] 大小超出系统限制的"+$('#file_upload').uploadify('settings','fileSizeLimit')+"大小！";
						this.queueData.errorMsg='所选文件大小超出系统限制!';
						break;
					case -120:
						//this.queueData.errorMsg="文件 ["+file.name+"] 大小异常！"
						this.queueData.errorMsg='所选文件大小异常!';
						break;
					case -130:
						//this.queueData.errorMsg="文件 ["+file.name+"] 类型不正确！"
						this.queueData.errorMsg='所选文件类型不正确!';
						break;
				}
			},
			'onCancel' : function(file){
				alert(file);
			}
		});
	});
	
	
	
	  //生成world文档
	  $("#generateWorld").click(function(){
			var id=$("#id").val();
				if(!top.$('#addProjectsDataForm').form('validate')){//表单校验是否通过
					$.messager.alert('提示',"请将信息填写完整或检查信息填写是否正确后点击生成Word!",'error',function(){});
					return;
				}

				//响应文件
				var responseFile="";
				$('.responseFile').each(function(){
					var val=$.trim($(this).val());
					if(val==""){
						val="-";
					}
					responseFile+=val+"@";
				});
				$("#responseFile").val(responseFile);
				
			 $.ajax({
					type: "post",
					url:  "${ctx}/business/projectNb/generateWord",
					data:top.$("#addProjectsDataForm").serialize(),
					success: function(data,res){
						var result = $.trim(res.responseText);
						if(result == "unLogin"){
							var msn = ''||i18n[''];
							msn = msn||i18n[result];
							if(msn != undefined){
								$.messager.alert('提示',msn,'info',function(){top.location='${ctx}/manage';});
								return ;
							}
						}
						$.messager.alert('提示',"生成成功！",'info');
						var result=eval("("+data+")");
						$.each(result,function(index,res){
							if(res.functionFlog==5){
								$("#establishFile").attr("href","javascript:showOpenFile('${ctx}','"+res.id+"','"+requestUrl+"');");
								$("#establishFile").html(res.oldName);
							}
						});
					},
					error: function(res){
						$.messager.alert('提示',i18n.requestError,'error');
					}
				});
		});

		
		//删除文件
		function deleteFile(v,resId){
			var parent = v.parentNode;
			parent.parentNode.removeChild(parent);
			var  budgetMenuData = $('#budgetMenuData').val();
	        var index = budgetMenuData.indexOf(","+resId)
	        if(index != -1){
	     	   budgetMenuData = budgetMenuData.replace(","+resId,"");
	     	   $('#budgetMenuData').val(budgetMenuData);
	        }

	        //删除数据库中的文件信息
	        $.ajax({
				type : "post",
				url : "${ctx}/business/projectmanage/deleteFile?resId="+resId,
				data : top.$("#addProjectsDataForm").serialize(),
				success : function(data){
					
				},
				error : function(data){
					alert("错误");
				}
			});
		}
		
		
		//开标时间选择事件
		$('#bidStartDateStr').datebox({
		      onSelect: function (date) {
		      	$('#bidStartTimeStr').combobox('setValues','');  
		      	
		      	//设置后审核时间,默认报价截止时间后1个工作日
	      		var isAfterAudit=$('input:radio[name="isAfterAudit"]:checked').val()
				debugger;
		      	if(isAfterAudit){//后审
		      		$.ajax({
						type: "post",
						async:false,
						url:  '${ctx}/business/projectmanage/computeWorkDayDate',
						data:{
							date:$('#bidStartDateStr').datebox('getValue')+" 00:00:00",
							addDay:1
						},
						success: function(data){
					    	$('#afterAuditDateStr').datebox('setValue', data);
						}
					});
		      	}
		      }
		});
		
		
		/*是否资质后审点击事件*/
		function isAfterAuditClick(isBid) {
		    if(isBid==1){//后审,显示
		    	$("#noAfterAudit").removeClass("st");
		    	$.ajax({
					type: "post",
					async:false,
					url:  '${ctx}/business/projectmanage/computeWorkDayDate',
					data:{
						date:$('#bidStartDateStr').datebox('getValue')+" 00:00:00",
						addDay:1
					},
					success: function(data){
				    	$('#afterAuditDateStr').datebox('setValue', data);
					}
				});
		    }else{//不后审,不显示
		    	$("#noAfterAudit").addClass("st");
		    	//设定一个固定的工作日期，保证不后审校验不通过
		    	$('#afterAuditDateStr').datebox('setValue', '2099-6-6');
		    }
	   	}
		
		//=================================easyui 校验============================================
		//确认截止时间必须超过当前时间
		$.extend($.fn.validatebox.defaults.rules, {
			dateTimeMoreCurrentCompare: {
				 validator: function (value, param) {
					$('#validTime').val(value);
					var beginDate = new Date(value.replace(/-/g,"/"));
					var currentTime=new Date();
					var maxDate=new Date((myformatter(beginDate)+" 16:30:00").replace(/-/g,"/"));
					if(beginDate.getTime()>maxDate.getTime()){//确认时间不能迟于16:30
						return false;
					}
					return beginDate.getTime()>currentTime.getTime();
				 },
				 message: '确认截止时间必须超过当前时间,且不能迟于16:30'
			 }
		 });



</script>

</html>

